package com.fengzhi.web.dao.ssh.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.fengzhi.web.dao.core.impl.GenericDaoImpl;
import com.fengzhi.web.dao.ssh.IUserDao;
import com.fengzhi.web.entity.TUser;

@Repository
public class UserDaoImpl extends GenericDaoImpl<TUser> implements IUserDao {

	@SuppressWarnings("unchecked")
	@Override
	public TUser findUserByUsername(String username) {
		log.info("根据用户名获取用户对象！");

		String hql = "from TbUser where username = ? ";
		Object[] values = new Object[] { username };
		List<TUser> userList = (List<TUser>) getHibernateTemplate().find(hql, values);

		if (userList != null && !userList.isEmpty()) {
			return userList.get(0);
		}

		return null;
	}

	@Override
	public void addUser(TUser user) {
		log.info("添加用户数据");
		save(user);
	}

}
